import { ProFormRate } from '@ant-design/pro-components';

const CommonFormRate: React.FC<any> = ({ required, rules = [], count, allowHalf, ...props }) => {
  return (
    <ProFormRate
      {...props}
      fieldProps={{
        count,
        allowHalf,
      }}
      rules={
        rules.some((rule: any) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `请评分${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormRate.defaultProps = { required: false };

export default CommonFormRate;
